// https://leetcode.cn/problems/binary-gap/
// Created by ade on 2022/8/17.
//
#include <iostream>


using namespace std;

class Solution {
public:
    int binaryGap(int n) {
        int c = 0, num = 0;
        while (n) {
            if (n & 1) {
                n >>= 1;
                break;
            } else {
                n >>= 1;
            }
        }
        while (n) {
            c++;
            if (n & 1) {
                num = max(num, c);
                c = 0;
            }
            n >>= 1;
        }
        return num;
    }
};

int main() {
    Solution so;
    auto res = so.binaryGap(22);
    cout << res << endl;
    return 0;
}